//
//  GKZYRegisteredController.m
//  GKZYAid
//
//  Created by lanou3g on 16/3/8.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//,

#import "GKZYRegisteredController.h"
#import "GKZYChatListController.h"
#import "DatabaseRongcloud.h"

@interface GKZYRegisteredController ()

@end

@implementation GKZYRegisteredController

- (void)loadView{
    
    self.regsiterView = [[GKZYRegsiterView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.view = self.regsiterView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
   
    //添加Landing事件:
    [self.regsiterView.buttonLanding addTarget:self action:@selector(buttonLandingAction:) forControlEvents:UIControlEventTouchUpInside];

}


//Landing登陆跳转事件
- (void)buttonLandingAction:(UIButton *)sender{
    
    if(self.regsiterView.textfiledID.text.length == 0)
    {
       
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"确定" message:@"用户ID不能为空" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        
        [alertVC addAction:sure];
        
        [self presentViewController:alertVC animated:YES completion:nil];
    }
    else
    {
        [DatabaseRongcloud shareIntance].userID = self.regsiterView.textfiledID.text;
    }
    
    [self getToken];
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)getToken
{
    [[DatabaseRongcloud shareIntance] getTokenWithBlock:^(NSString *token) {
        
        [[RCIM sharedRCIM] connectWithToken:token success:^(NSString *userId) {
            
        } error:^(RCConnectErrorCode status) {
            
        } tokenIncorrect:^{
            
        }];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];


}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
